﻿using System;
using System.Collections.Generic;
using System.IO;
using Boggle.Net.Model;

namespace Boggle.Net.Console
{
    class Program
    {
        static void Main()
        {
            var random = new Random();

            foreach (var line in Search(Tray.FilledWith(Game.SelectJumbledLetters(random.Next))))
                System.Console.WriteLine(line);
        }

        private static IEnumerable<string> Search(Tray tray)
        {
            var dictionary = EnhancedNorthAmericanBenchmarkWordList;

            yield return tray.ToString();

            var time = DateTime.Now;
            var totalFound = 0;

            foreach (var result in tray.FindAllWordsIn(dictionary))
            {
                yield return result.Word + " " + result.Path.AsString();
                ++totalFound;
            }

            yield return String.Format("Total found: {0} ({1})", totalFound, DateTime.Now - time);
        }

        static IWordList EnhancedNorthAmericanBenchmarkWordList
        {
            get
            {
                // ReSharper disable AssignNullToNotNullAttribute
                var fullPath = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), @"..\..\..\ENABLE.txt");
                // ReSharper restore AssignNullToNotNullAttribute
                return new BasicWordList(fullPath);
            }
        }
    }
}
